package com.base.data.elasticsearch.repository.query;


import com.base.data.elasticsearch.annotations.Query;
import org.springframework.core.annotation.AnnotationUtils;
import org.springframework.data.projection.ProjectionFactory;
import org.springframework.data.repository.core.RepositoryMetadata;
import org.springframework.data.repository.query.QueryMethod;

import java.lang.reflect.Method;

/**
 * ElasticsearchQueryMethod
 */
public class BaseElasticsearchQueryMethod extends QueryMethod {

    private final Query queryAnnotation;

    public BaseElasticsearchQueryMethod(Method method, RepositoryMetadata metadata, ProjectionFactory factory) {
        super(method, metadata, factory);
        this.queryAnnotation = method.getAnnotation(Query.class);
    }

    public boolean hasAnnotatedQuery() {
        return this.queryAnnotation != null;
    }

    public String getAnnotatedQuery() {
        return (String) AnnotationUtils.getValue(queryAnnotation, "value");
    }
}
